

alter         trigger tfb_wagedivide_bi on tfb_wagedivide
instead of insert
as   
begin
  set nocount on
  declare @bid int, @relmonthbid varchar(1000), @sql nvarchar(2000)

  declare tfb_wagedivide_cr cursor local forward_only static optimistic 
  for select distinct bid,relmonthbid from inserted
  open tfb_wagedivide_cr
  fetch next from tfb_wagedivide_cr into @bid,@relmonthbid
  while @@fetch_status = 0
  begin
    set @sql=N'update tfb_wagemonth set reldividebid='+cast(@bid as varchar)+' where bid in ('+@relmonthbid+')'
    exec sp_executesql @sql
    fetch next from tfb_wagedivide_cr into @bid,@relmonthbid
  end
  insert into tfb_wagedivide select * from inserted
  close tfb_wagedivide_cr
  deallocate tfb_wagedivide_cr 
end


















